<extend name="Base/common"/>
<!--<script type="text/javascript" src="/SG_Shopwechat/Public/Home/js/iscroll.js"></script>-->
<block name="TITLE"><title>采购申请</title></block>
<block name="body" >
    <header data-am-widget="header" class="am-header am-header-default am-header-fixed">
        <div class="am-header-left am-header-nav">
            <a href="{:U('Purchase/index')}" class="">
                <i class="am-header-icon am-icon-home"></i>
            </a>
        </div>
        <h1 class="am-header-title">
            <a href="#title-link" class="">
                &nbsp;{$title}
            </a>
        </h1>

    </header>
    <div class="" >
        <form class="am-form am-form-horizontal" action="{:U('Purchase/updatePurchase')}" method="POST">
            <div class="am-form-group">
                <label for="proName" class="am-u-sm-3 am-form-label">商品名称</label>
                <div class="am-u-sm-9">

                    <input class="am-form-field" name="proName" id="proName" type="text" placeholder="输入商品名称" value="{$purchase.proName}"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="spec" class="am-u-sm-3 am-form-label">单箱规格</label>
                <div class="am-u-sm-3">
                    <input class="am-form-field" name="spec" id="spec" type="hidden"  placeholder="输入单箱规格" value="{$purchase.spec}"/>
                    <input class="" name="head" id="head" type="text" value="{$purchase.head}"/>
                </div>
                <label for="spec" class="am-u-sm-1 am-form-label">头</label>
                <div class="am-u-sm-3">
                    <input class="" name="jin" id="jin" type="text"  value="{$purchase.jin}"/>
                </div>
                <label for="spec" class="am-u-sm-2 am-form-label">斤</label>
            </div>

            <div class="am-form-group">
                <label for="grossWeight" class="am-u-sm-3 am-form-label">总重量</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="grossWeight" id="grossWeight" type="text"  onblur="getNetWeight()" placeholder="输入总重量 斤" value="{$purchase.grossWeight}"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="number" class="am-u-sm-3 am-form-label">采购件数</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="number" id="number" type="text" onblur="getAmount();" placeholder="输入采购件数" value="{$purchase.number}"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="price" class="am-u-sm-3 am-form-label">采购单价</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="price" id="price" type="text" onblur="getAmount();" placeholder="输入采购单价 元" value="{$purchase.price}"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="boxheavy" class="am-u-sm-3 am-form-label">箱重</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="boxheavy" id="boxheavy" type="text" onblur="getNetWeight()" placeholder="输入箱重 斤" value="{$purchase.boxheavy}"/>
                </div>
            </div>
            
            <div class="am-form-group">
                <label for="netWeight" class="am-u-sm-3 am-form-label">净重</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="netWeight" id="netWeight" type="text" placeholder="输入净重 斤" value="{$purchase.netWeight}"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="amount" class="am-u-sm-3 am-form-label">采购总价</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="amount" id="amount" type="text" placeholder="输入采购总价 元" value="{$purchase.amount}"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="boxfee" class="am-u-sm-3 am-form-label">箱费</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="boxfee" id="boxfee" type="text" placeholder="输入箱费 元" value="{$purchase.boxfee}"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="loss" class="am-u-sm-3 am-form-label">损耗</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="loss" id="loss" type="text" placeholder="输入损耗：5%" value="{$purchase.loss}"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="selflife" class="am-u-sm-3 am-form-label">存放期</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="selflife" id="selflife" type="text" placeholder="输入存放期" value="{$purchase.selflife}"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="shopName" class="am-u-sm-3 am-form-label">产地</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="locality" id="shopName" type="text" placeholder="输入产地" value="{$purchase.locality}"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="shopName" class="am-u-sm-3 am-form-label">商户名称</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="shopName" id="shopName" type="text" placeholder="输入商户名称" value="{$purchase.shopName}"/>
                </div>
            </div>
            
<!--            <div class="am-form-group">
                <label for="unit" class="am-u-sm-3 am-form-label">采购单位</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="unit" id="unit" type="text" placeholder="输入采购单位" value="{$purchase.unit}"/>
                </div>
            </div>
            <div class="am-form-group">
                <label for="shopPhone" class="am-u-sm-3 am-form-label">商户电话</label>
                <div class="am-u-sm-9">
                    <input class="am-form-field" name="shopPhone" id="shopPhone" type="text" placeholder="输入商户电话" value="{$purchase.shopPhone}"/>
                </div>
            </div>
            <div class="am-form-group">
                <label for="arriveTime" class="am-u-sm-3 am-form-label">预计到货时间</label>
                <div class="am-u-sm-9">
                    <input type="date" class="am-form-field" name="arriveTime" id="arriveTime" placeholder="输入预计到货时间" value="{$purchase.arriveTime}">
                    <input class="am-form-field" name="arriveTime" id="arriveTime" type="text" placeholder="输入预计到货时间" data-am-datepicker readonly required />
                </div>
            </div>-->
            <div class="am-form-group">
                <div class="am-u-sm-12">
                    <input type="hidden" name="id" value="{$purchase.id}" />
                    <button type="submit" class="am-btn am-btn-primary am-btn-block">提交至采购单</button>
                </div>
            </div>
        </form>
    </div>
</block>
<block name="script">

    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

    <script type="text/javascript">
        
        //自动算出 采购总价 （采购总价 ＝ 采购件数 * 采购单价）
        function getAmount(){
            number = $("#number").val();        //采购件数
            price = $("#price").val();          //采购单价
            $("#amount").val(number * price );  //采购总价
            
            grossWeight = $("#grossWeight").val();        //总重量
            boxheavy = $("#boxheavy").val();              //箱重
            $("#netWeight").val((grossWeight - (number * boxheavy)) / number);  //净重
        }

        //自动算出 净重 （净重 ＝ （总重量 －（采购件数 * 箱重））/ 采购件数）
        function getNetWeight(){
            grossWeight = $("#grossWeight").val();        //总重量
            number = $("#number").val();                  //采购件数
            boxheavy = $("#boxheavy").val();              //箱重
            $("#netWeight").val((grossWeight - (number * boxheavy)) / number);  //净重
        }
    </script>
</block>
